package com.little.test.client;

import com.little.test.api.IHello;
import com.little.test.api.IHello2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by ChengPeng on 2017/6/16.
 */
public class ClientBootstrap {
    @Autowired
    private IHello aa;
    @Autowired
    private IHello2 bb;
    private void doSomething(){

        System.out.println("doSomething：" + aa);
        System.out.println("doSomething：" + bb);

        String hello1 = aa.sayHello("Rpc");
        Integer hello2 = bb.doubleNum(10);

        System.out.println("hello1:" + hello1 + " hello2 " + hello2);
    }


    public static void testByFactoryBean(ApplicationContext context){
        IHello aa = (IHello) context.getBean(IHello.class);
        IHello2 bb = (IHello2) context.getBean("bb");

        System.out.println("testByFactoryBean:"+aa);
        System.out.println("testByFactoryBean:"+bb);

        String hello1 = aa.sayHello("Rpc");
        Integer hello2 = bb.doubleNum(10);

        System.out.println("hello1:" + hello1 + " hello2 " + hello2);
    }

    public static void testByAutowrite(ApplicationContext context){

        ClientBootstrap c = (ClientBootstrap) context.getBean("client");
        c.doSomething();
    }


    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:rpc-client.xml");
        testByAutowrite(context);
        testByFactoryBean(context);
    }


}
